
xdata = [
        ['小泉纯一郎', '小犬'],
        ['毛泽东', '润之'],
        [None, None],
        ['毛泽东', '毛主席'],
        ['平', None],
        ['刘备', '大耳'],
        [None, '习近平'],
        ['刘皇叔', '刘玄德'],
        ['刘备', '刘玄德'],
        ['金三胖', '金正恩'],
        [None, '金正日'],
        ['金正日', '金二胖'],
    ]
shuchui={}
zi=0
def yuce(zi,shuchu):
    for  z in xdata:
        tianjia=0
        i,j=z
        if i==None or j==None:
            continue
        if zi==0:
            shuchu[zi]=z
        else :
            for x in range(len(shuchu)):
                if i in shuchu[x] and j in shuchu[x]:
                    tianjia = 1
                    continue
                for m in shuchu[x]:
                    print(m)
                    if m==i :
                        shuchu[x]=shuchu[x]+[j]
                        tianjia=1
                        break
                    elif m==j :
                        shuchu[x]=shuchu[x]+[i]
                        tianjia=1
                        break
        if tianjia==0:
            shuchu[zi]=z
        else:
            continue
        zi+=1

    return shuchu
def quchong(shuchu):
    zong=len(shuchu)
    for j in range(len(shuchu)):
        tiao=0
        for z in shuchu[j]:
            if tiao>0:
                del shuchu[j]
                zong-=1
                break
            for x in shuchu[j+1]:
                if z==x:
                    tiao+=1
        if j+1==zong:
            break
    return shuchu

# def tianjia(shuchui):
#     for i,j in xdata:
#         if i==None and j==None:
#             continue
#         elif i==None:
#             for z in range(len(shuchui)):
#                 for q in shuchui[z]:
#                     if j==q:
#                         break
#

for i in range(5):
    shuchui=yuce(zi,shuchui)
    # shuchui=tianjia(shuchui)
print(quchong(shuchui))



# 输出：
# ('平',)
# ('刘皇叔', '大耳', '刘玄德', '刘备')
# ('小泉纯一郎', '小犬')
# ('润之', '毛泽东', '毛主席')
# ('金三胖', '金正恩')
# ('金正日', '金二胖')
